#include<string>
using namespace std;
class Solution {
public:
    bool backspaceCompare(string s, string t) {
        string st1;
        string st2;
        for (auto& e : s) {
            if (e != '#')
                st1.push_back(e);
            else if (e == '#') {
                if (st1.length())
                    st1.pop_back();
            }
        }
        for (auto& e : t) {
            if (e != '#')
                st2.push_back(e);
            else if (e == '#') {
                if (st2.length())
                    st2.pop_back();
            }
        }

        return st1 == st2;
    }
};